package com.prs.crm.action.person;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.person.MarriageState;
import com.prs.crm.service.person.MarriageStateService;

public class MarriageStateAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private MarriageState marriageState;
	private MarriageStateService marriageStateService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public MarriageState getMarriageState() {
		return marriageState;
	}
	public void setMarriageState(MarriageState marriageState) {
		this.marriageState = marriageState;
	}
	public MarriageStateService getMarriageStateService() {
		return marriageStateService;
	}
	public void setMarriageStateService(MarriageStateService marriageStateService) {
		this.marriageStateService = marriageStateService;
	}
	
	@Action("listMarriageState")
	public String listMarriageState(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(MarriageState.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getMarriageStateService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("editMarriageState")
	public String editMarriageState(){
		if(ids!=null){
			this.marriageState=this.getMarriageStateService().get(ids[0]);
		}
		return SUCCESS;
	}
	
	@Action(value="saveMarriageState",results={
			@Result(name="success",type="redirect",location="listMarriageState"),
			@Result(name="error",type="chain",location="editMarriageState")
	})
	public String saveMarriageState(){
		this.getMarriageStateService().save(marriageState);
		return SUCCESS;
	}
	
	@Action(value="removeMarriageState",results={
			@Result(name="success",type="redirect",location="listMarriageState"),
			@Result(name="error",type="chain",location="listMarriageState")
	})
	public String removeMarriageState(){
		if(ids==null){
			this.addActionError("请选择一行进行操作！");
			return ERROR;
		}
		this.getMarriageStateService().batchRemove(ids);
		return SUCCESS;
	}
}
